import { useState, useEffect } from 'react'
import { useFetch } from '@/plugins/axios'
import { SystemInfoProps } from '@/utils/interface'
import { FetchSystemInfoProps, transSystemInfo } from '@/utils/translator'
export const useSystemInfo = () => {
	const [systemInfo, setSystemInfo] = useState<SystemInfoProps>({})

	const [{ loading, data }, reFetch] = useFetch<FetchSystemInfoProps>(
		{
			url: 'sas/system/info',
			method: 'get',
		},
		{
			cacheKey: 'systemInfo',
			cacheTime: Infinity,
		}
	)
	useEffect(() => {
		if (!loading) {
			if (data) {
				let _data = transSystemInfo(data)
				setSystemInfo(_data)
			}
		}
	}, [data, loading])

	return { systemInfo, reFetch }
}
